package com.lcl.jarvis.dto;

import com.lcl.jarvis.entity.TbUserAuthDO;
import org.springframework.beans.BeanUtils;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 转换
 */
public class TbUserAuthDtoAssembler {

    private TbUserAuthDtoAssembler() {
        // hide for utils
    }

    /**
     * 转换为DTO对象
     *
     * @param value
     * @return
     */
    public static TbUserAuthDTO toTbUserAuthDto(TbUserAuthDO value) {
        if (value == null) {
            return null;
        }
        TbUserAuthDTO dto = new TbUserAuthDTO();
        BeanUtils.copyProperties(value, dto);
        return dto;
    }

    /**
     * 转换为实体对象
     *
     * @param dto
     * @return
     */
    public static TbUserAuthDO toTbUserAuthDo(TbUserAuthDTO dto) {
        if (dto == null) {
            return null;
        }
        TbUserAuthDO value = new TbUserAuthDO();
        BeanUtils.copyProperties(dto, value);
        return value;
    }

    /**
     * 转换为DTO对象list
     *
     * @param tbUserAuths
     * @return
     */
    public static List<TbUserAuthDTO> toTbUserAuthDtoList(List<TbUserAuthDO> tbUserAuths) {
        if (tbUserAuths == null) {
            return null;
        }
        return tbUserAuths.stream().map(TbUserAuthDtoAssembler::toTbUserAuthDto).collect(Collectors.toList());
    }

    /**
     * 转换为实体对象list
     *
     * @param dtos
     * @return
     */
    public static List<TbUserAuthDO> toTbUserAuthDoList(List<TbUserAuthDTO> dtos) {
        if (dtos == null) {
            return null;
        }
        return dtos.stream().map(TbUserAuthDtoAssembler::toTbUserAuthDo).collect(Collectors.toList());
    }

}
